﻿#region << 文件说明 >>
/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls
 * 唯一标识：8dc89482-aedd-4b6a-9507-33d460f81f7b
 * 文件名：TestControl
 * 
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/7/8 10:38:57
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 文件说明 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Vampirewal.BlogCore;

/// <summary>
/// 测试控件
/// </summary>
public sealed class TestControl:ControlBase
{
    /// <summary>   
    /// 构造函数
    /// </summary>
    public TestControl()
    {
        tableData = new List<TableData>();
    }

    public override string Id { get; set; }
    public override string Title { get; set; }

    public override string ConverToHtml()
    {
        var html = new StringBuilder();

        // 开始表格
        html.Append("<div style=\"border: 1px solid black; padding: 10px;\">");

        // 表头
        html.Append("<el-row class=\"table-row header-row\">");
        html.Append("<el-col :span=\"4\" class=\"table-col\">日期</el-col>");
        html.Append("<el-col :span=\"4\" class=\"table-col\">姓名</el-col>");
        html.Append("<el-col :span=\"4\" class=\"table-col\">地址</el-col>");

        html.Append("<el-col :span=\"4\" class=\"table-col\">列4</el-col>");
        html.Append("<el-col :span=\"4\" class=\"table-col\">列5</el-col>");
        html.Append("</el-row>");

        // 表格主体
        foreach (var data in tableData)
        {
            html.Append("<el-row class=\"table-row\">");
            html.Append($"<el-col :span=\"4\" class=\"table-col\">{data.Date}</el-col>");
            html.Append($"<el-col :span=\"4\" class=\"table-col\">{data.Name}</el-col>");
            html.Append($"<el-col :span=\"4\" class=\"table-col\">{data.Address}</el-col>");
            html.Append("<el-col :span=\"4\" class=\"table-col\">数据4</el-col>");
            html.Append("<el-col :span=\"4\" class=\"table-col\">数据5</el-col>");
            html.Append("</el-row>");
        }

        // 结束表格
        html.Append("</div>");

        return html.ToString();
    }

    public List<TableData> tableData { get; set; }
}

public class TableData
{
    public string Date { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
}

public static partial class App
{
    public static TestControl CreateTestControl(string title,Action<List<TableData>> tableDataAction)
    {
        TestControl test = new TestControl()
        {
            Id = GenerateId(),
            Title = title,
        };

        tableDataAction.Invoke(test.tableData);

        return test;
    }
}